package com.ssn.reflect;

import java.lang.reflect.Method;

public class InvokeTest
{
	public int add(int param1, int param2)
	{
		return param1 + param2;
	}

	public String echo(String msg)
	{
		return "hello: " + msg;
	}

	public static void main(String[] args) throws Exception
	{
		Class<?> myClass = Class.forName("com.ssn.reflect.InvokeTest");
		Class<?> myClass2 = InvokeTest.class;
		Object myInvokeTest = myClass2.newInstance();

		Method addMethod = myClass2.getMethod("add", new Class[] { int.class,
				int.class });
		Object result = addMethod.invoke(myInvokeTest, new Object[] { 1, 2 });
		System.out.println((Integer) result);
		System.out.println("____________________________");
		Method echoMethod = myClass2.getMethod("echo",
				new Class[] { String.class });
		Object res2 = echoMethod.invoke(myInvokeTest, "world");
		System.out.println((String) res2);
	}
}
